var TutorialToken = artifacts.require("./TutorialToken.sol");

contract('TutorialToken', function(accounts) {
    it("should send coin correctly", function() {
        var meta;

        var account_one = accounts[0];
        var account_two = "0x5B635E6eC33DE4b3c6e68Fb6474DB50A9c395522";

        var account_one_starting_balance;
        var account_two_starting_balance;
        var account_one_ending_balance;
        var account_two_ending_balance;

        var amount = Math.pow(10, 6);

        return TutorialToken.deployed().then(function(instance) {
            meta = instance;
            return meta.balanceOf.call(account_one);
        }).then(function(balance) {
            account_one_starting_balance = balance.toNumber();
            return meta.balanceOf.call(account_two);
        }).then(function(balance) {
            account_two_starting_balance = balance.toNumber();
            return meta.transfer(account_two, amount, {from: account_one});
        }).then(function() {
            return meta.balanceOf(account_one);
        }).then(function(balance) {
            account_one_ending_balance = balance.toNumber();
            return meta.balanceOf(account_two);
        }).then(function(balance) {
            account_two_ending_balance = balance.toNumber();

            assert.equal(account_one_ending_balance, account_one_starting_balance - amount, "Amount wasn't correctly taken from the sender.");
            assert.equal(account_two_ending_balance, account_two_starting_balance + amount, "Amount wasn't correctly sent to the receiver.");
        });
    })
});